package cn.momoshenchi.service;

import cn.momoshenchi.dao.StudentMapper;
import cn.momoshenchi.dao.StudentResumeMapper;
import cn.momoshenchi.pojo.Student;
import cn.momoshenchi.pojo.StudentResume;
import cn.momoshenchi.util.AssertUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version : 1.0
 * @author: momoshenchi
 * @date: 2021/4/20 - 14:41
 */
@Service
public class StudentResumeService
{
    @Resource
    private StudentResumeMapper studentResumeMapper;

    @Resource
    private StudentMapper studentMapper;

    public void add(StudentResume studentResume)
    {
        AssertUtil.isTrue( studentResumeMapper.insert(studentResume)!=1,"增加失败");
    }

    public void update(StudentResume studentResume)
    {
        AssertUtil.isTrue(studentResumeMapper.updateByPrimaryKey(studentResume)!=1,"更新失败");
    }
    public void delete(Integer id)
    {
        AssertUtil.isTrue(studentResumeMapper.deleteByPrimaryKey(id)!=1,"删除失败");
    }


    public Map<String,Object> selectByStudentId(String  studentId)
    {
        Map<String, Object> map=new HashMap<>();
        Student student = studentMapper.selectByStudentId(studentId);
        AssertUtil.isTrue(student==null,"学生不存在");
        Map<String, Object> data = studentResumeMapper.selectByStudentId(studentId);
        if(data==null)
        {
            data=new HashMap<>();
        }
        data.put("studentId",student.getStudentId());
        data.put("email", student.getEmail());
        data.put("gender", student.getGender());
        map.put("code", 200);
        map.put("msg", "成功");
        map.put("data",data);
        return map;
    }

    public Map<String,Object> selectById(Integer  id)
    {
        Map<String, Object> map=new HashMap<>();
        StudentResume studentResume = studentResumeMapper.selectByPrimaryKey(id);
        map.put("code", 200);
        map.put("msg", "成功");
        map.put("data",studentResume);
        return map;
    }
}
